var tableData = {
	checkAll:function()
	{
		$(':checkbox').each(function(i,item){
			if(item.name == 'checkTableData')
			{
				item.checked = true;
			}
		});
	},

	checkNone:function()
	{
		$(':checkbox').each(function(i,item){
			if(item.name == 'checkTableData')
			{
				item.checked = false;
			}
		});
	},

	check:function(row)
	{
		var checkbox = row.childNodes[0].childNodes[0];
		if(checkbox.checked)
		{
			checkbox.checked = false;
		}
		else
		{
			checkbox.checked = true;
		}
	},

	highlight:function(row)
	{
		var checkbox = row.childNodes[0].childNodes[0];
		if(checkbox.checked)
		{
			row.style.backgroundColor='#facdcd';
		}
		else
		{
			row.style.backgroundColor='#dbf3c0';
		}
	},

	draw:function(fields,data)
	{
		var tdWidth = Math.floor(100/fields.length);
		var tdsHeader = ''+
			'<tr>'+
				'<td><img src="images/butRowArrow.gif" border="0"></td>'+
				'<td colspan="2" class="fontTahoma size8" align="center" width="60">'+
					'<a href="javascript:void(0);" onclick="tableData.checkAll();">[all]</a> '+
					'<a href="javascript:void(0);" onclick="tableData.checkNone();">[none]</a>'+
				'</td>';

		/* Create Fields Rows */
		$.each(fields,function(i,item){
			if(item.Key == 'PRI')
			{
				var keyImg = '<img src="images/tablePrimaryKey.jpg" align="absmiddle" border="0">';
			}
			else
			{
				var keyImg = '';
			}
			var title = item.Type;
			tdsHeader += '<td class="tableHeader fontTahoma size14 bold underline" width="'+tdWidth+'%" title="'+title+'">'+keyImg+item.Field+'</td>';
		});
		tdsHeader += '</tr>';

		/* Create Data Rows */
		var tds = '';
		$.each(data,function(i,item){
			tds += '<tr onmouseover="tableData.highlight(this)" onmouseout="this.style.backgroundColor=\'#ffffff\'">'+
								'<td width="25" class="borderGray">'+
									'<input type="checkbox" name="checkTableData">'+
								'</td>'+
								'<td width="25" class="borderGray">'+
									'<a href="javascript:void(0);" title="Edit Row">'+
										'<img src="images/butRowEdit.gif" border="0">'+
									'</a>'+
								'</td>'+
								'<td width="25" class="borderGray">'+
									'<a href="javascript:void(0);" title="Delete Row">'+
										'<img src="images/butRowDelete.gif" border="0">'+
									'</a>'+
								'</td>';
			$.each(item,function(z,content){
				tds += ''+
					'<td class="borderGray fontCourier size12" width="'+tdWidth+'%" title="'+z+'" onclick="tableData.check(this.parentNode)">'+
						'<div class="tableConent">'+content+'</div>'+
					'</td>';
			});
			tds += '</tr>';
		});
		$('#divMainContent').append('<table class="tableData" cellpadding="5" cellspacing="3" id="tableData">'+tdsHeader+tds+'</table>');
	}
};